package priv.pront.code.national.acwing.dp.linear.lis;

import java.io.IOException;
import java.util.Scanner;

public class Acwing1014_登山 {

    static final int N = 1010;
    static int[] f1 = new int[N]; //f1[i]表示正着的以i结尾的最长上升子序列的长度
    static int[] f2 = new int[N]; //f2[i]表示倒着的以i结尾的最长上升子序列的长度
    static int n;
    static int[] h = new int[N];
    static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) throws IOException {
        n = scan.nextInt();
        for (int i = 1; i <= n; i++) h[i] = scan.nextInt();

        //正LIS
        for (int i = 1; i <= n; i++) {
            f1[i] = 1;
            for (int j = 1; j < i; j++)
                if (h[j] < h[i]) f1[i] = Math.max(f1[i], f1[j] + 1);
        }
        //倒LIS
        for (int i = n; i >= 1; i--) {
            f2[i] = 1;
            for (int j = n; j > i; j--)
                if (h[j] < h[i]) f2[i] = Math.max(f2[i], f2[j] + 1);
        }
        int res = 0;
        for (int i = 1; i <= n; i++) res = Math.max(res, f1[i] + f2[i] - 1); //减去多加的一个转折点
        System.out.println(res);
    }
}
